<template>
  <div class="posiMaIndex">
    <userHeader />
    <div class="breadClum">
      <span>
          <router-link :to="{path:'/pageIndex'}">   <a class="bread1">当前位置：首页  >  </a></router-link>
        <router-link :to="{path:'/systemSetting'}">    <a class="bread2">系统设置  ></a></router-link>
          <a class="bread2">角色管理</a>
      </span>
    </div>
    <div class="navList">
          <span style="margin-left: 20px">
            <router-link :to="{path:'/addPosi'}">
               添加角色
              </router-link>
          </span>
    </div>
    <el-table
      :row-class-name="tableRowClassName"
      ref="tableData3"
      :data="tableData3"
      :height="height"
      style="width: 100%">
      <el-table-column
          label="ID"
          prop="role_id"
        width="70">
      </el-table-column>
      <el-table-column
        prop="role_name"
        label="角色"
        width="125">
      </el-table-column>
      <el-table-column
        prop="role_desc"
        label="角色描述"
        width="195">
      </el-table-column>
      <el-table-column
        prop="role_type_text"
        label="角色类型"
        width="185">
      </el-table-column>
      <el-table-column
        prop="appraise_type_text"
        label="评价类型"
        width="185">
      </el-table-column>
      <el-table-column
        prop="opt"
        label="操作"
        width="200">
        <template slot-scope="scope">
          <router-link :to="{path:'/addPosi',query:{role_id:scope.row.role_id,index:scope.row.index,appraise_type:scope.row.appraise_type,role_type:scope.row.role_type}}">
            <span  class="e-ditor">编辑</span>
          </router-link>
              <span @click.stop="delete1(scope.row.role_id,scope.row.index,scope.row.appraise_type,scope.row.role_type)" class="d-elete">删除</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="blank"
        label=""
        width="auto">
      </el-table-column>
    </el-table>
    <el-pagination
      :page-count=pageSize
      layout="total,prev, pager, next, jumper"
      :current-page.sync="currentPage"
      @current-change="currentChange"
    >
    </el-pagination>
    <el-dialog title="角色编辑" :visible.sync="dialogFormVisible" :before-close="handleClose">
      <el-form :model="form" >
        <el-form-item label="角色名称" :label-width="formLabelWidth" prop="role_name">
          <el-input v-model="form.role_name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="描述" :label-width="formLabelWidth" prop="role_desc">
        <el-input v-model="form.role_desc" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="评价类型" :label-width="formLabelWidth" prop="appraise_type_text">
          <el-select v-model="form.appraise_type" placeholder="请选择活动区域">
            <el-option label="评级人员" value="1"></el-option>
            <el-option label="非评级人员" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="角色类型" :label-width="formLabelWidth" prop="role_type_text">
          <el-select v-model="form.role_type" placeholder="请选择活动区域">
            <el-option label="集团" value="1"></el-option>
            <el-option label="子公司" value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelEditior">取 消</el-button>
        <el-button type="primary" @click="confirmEditor">确 定</el-button>
      </div>
    </el-dialog>
    <deleteAlarm @cancelOpt="cancelOpt" @confirmOpt="confirmOpt" :dialogVisible2="dialogFormVisible2"/>
  </div>
</template>

<script>
  import userHeader from '@/components/header.vue'
  import paganition from '@/components/paganition.vue'
  import deleteAlarm from '@/components/deleteAlarm.vue'
  import {strToHexCharCode,toFixedBit,dec2hex,formatTime,getNewDate } from  '@/utils/index.js';
  import {mapState} from 'vuex'
  var mdSecret ='fangyou968123456'
  export default({
    components:{
      userHeader,
      paganition,
      deleteAlarm

    },
    computed: {
      ...mapState({
        height:state=>sessionStorage.getItem('height')||state.app.height,
      }),
    },
    data (){
      return {
        dialogFormVisible:false,
        dialogFormVisible2:false,
        formLabelWidth:'160px',
        page:1,
        pageSize:1,
        i:0,
        total:0,
        currentPage:1,
        pageCount:0,
        role_id:'',
        role_type:'',
        appraise_type:'',
        id:'',
        index:'',
        form: {
          name: '',
          desc:'',
          region:''
        },
        tableData3: []
      }
    },
    methods: {
      tableRowClassName ({row, rowIndex}) {
        //把每一行的索引放进row
        row.index = rowIndex;
      },
      handleClose(){
        this.form={}
        this.dialogFormVisible=false
      },
      //分页状态改变
      currentChange(val){
        this.page =val
        this.initData( this.page)
      },
      confirmOpt(){
        this.axios.delete('/api/v1/system/role/'+`${this.id}`)
          .then((res)=>{
            console.log(res.data)
            this.$alert(res.data.message,'提示');
            if(res.data.code==0){
              this.tableData3.splice(this.index,1)
            }
          })
        this.dialogFormVisible2 =false;
      },
      cancelOpt(){
        console.log(456)
        this.dialogFormVisible2 =false
      },
      cancelEditior(){
        console.log('取消编辑')
        this.dialogFormVisible=false
      },
      confirmEditor(){
        console.log('角色类型',this.form.role_type)
        console.log('评价类型',this.form.appraise_type)
        this.axios.put('/api/v1/system/role/'+`${this.role_id}`,
          {
            role_id:this.role_id,
            role_name:this.form.role_name,
            role_desc:this.form.role_desc,
            appraise_type:this.form.appraise_type,
            role_type:this.form.role_type,
          })
          .then((res)=>{
            if(res.data.code==0){
            console.log(res)
              this.dialogFormVisible =false
            }
          }).catch((err)=>{
          this.$alert(err.message,'提示')
        })
        console.log('确认编辑')
      },
      editor(id,index,appraise_type,role_type){
          console.log(id,index,appraise_type,role_type)
        this.getEditor(id,index)
        this.role_id=id
        this.index=index
        this.appraise_type= appraise_type
        this.dialogFormVisible =true
        this.role_type=role_type
      },
      delete1(id,index,role_id){

        this.id=id
        this.index=index
        this.role_id= role_id
        this.dialogFormVisible2 =true;
//        alert(this.role_id)
      },
      initData(page){
        this.axios.get('/api/v1/system/role',{
            params:{
              limit:10,
              page
            }
        })
          .then((res)=>{
            if(res.data.code==0){
              this.tableData3 =res.data.data;
              this.total = res.data.pagination.total
              this.pageSize =res.data.pagination.pages
              this.currentPage=res.data.pagination.page
            }
          }).catch((err)=>{
          this.$alert(err.message,'提示')
        })
      },
      getEditor(id,index){
        this.axios.get('/api/v1/system/role/'+`${id}`)
          .then((res)=>{
            if(res.data.code==0){
              this.form =res.data.data
            }else{
              this.$alert(res.data.message,'提示')
            }
          }).catch((err)=>{
          this.$alert(err.message,'提示')
        })
      }
    },
    mounted(){
        this.initData(this.page)
    }
  })
</script>
<style scoped="">
  .posiMaIndex{
    width: 100%;
    height: 100%;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    padding:10px;
  }
  .posiMaIndex .el-table  >>>  th.is-leaf{
    background: #d3e9bb;
    height:58px;

  }
  .posiMaIndex  .el-table  >>> thead  th.is-leaf .cell{
      font-size: 14px;
      color: #5d9120;
      font-weight: normal;
    text-align: center;
  }
  .posiMaIndex  .el-table  >>> tr  th.is-leaf{
      border-bottom: 1px solid #aac983;
      border-right: 1px solid #aac983;
      border-top: 1px solid #aac983;
  }
  .posiMaIndex  .el-table  >>> .el-table__body-wrapper{
  }
  .posiMaIndex .el-table  >>> .el-table__body-wrapper  .el-table__body  .el-table__row{
    height: 50px !important;
  }
  .posiMaIndex  .el-table >>> .el-table__body-wrapper   .el-table__body  .el-table__row td{
      height: 50px;
      border-bottom: 1px solid #aac983;
      border-right: 1px solid #aac983;
  }
  .posiMaIndex .el-table  >>> .el-table__body-wrapper  .el-table__body  .el-table__row .cell{
      text-align: center;
  }
  .posiMaIndex .el-table >>>  span{
    color: #4577bf;
    text-decoration: underline;
  }

 .posiMaIndex .el-table >>>  span.e-ditor{
    margin-right:24px ;
  }
 .posiMaIndex >>> .el-dialog   .el-input{
      width: 380px;
  }

  @media screen and (max-width: 1400px) {
    .posiMaIndex{
      padding: 6px;
    }
  }
  /*.el-table >>> .el-table_1_column_6 .*/
</style>
<style>


</style>
